/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.registration.web;

import com.registration.ManagedBean;
import com.registration.core.Person;
import static org.apache.commons.lang.StringUtils.isBlank;

/**
 * @date May 10, 2012
 *
 * @author ggutierrez
 */
public class PersonBean extends ManagedBean {

    private Person person;

    public PersonBean() {
    }

    @Override
    public void reset() {
        super.reset();
    }

    @Override
    public String cancel() {
        return "success";
    }

    public String init() {
        reset();
        person = new Person();
        return "success";
    }

    public String save() {
        if (person != null){
            if (isBlank(person.getFullName())){
                addErrorMessage("Nombre es requerido");
            }
            if (isBlank(person.getEmail())){
                addErrorMessage("Correo es requerido");
            }
        }
        
        
        getManager().store(person);
        return "success";
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }
}
